﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;

namespace FDSimpleModelGenerator.Entities.CreateTables
{
    /// <summary>
    /// 列索引
    /// </summary>
    [Table("col_index")]
    public class ColumnIndex : Entity
    {
        public string IndexName1 { get; set; }
        public string IndexName2 { get; set; }
        public string IndexName3 { get; set; }
        public string IndexName4 { get; set; }
        public string IndexName5 { get; set; }
        public bool UniqueIndex { get; set; }

        /// <summary>
        /// 转化为有效索引列
        /// </summary>
        /// <returns></returns>
        public IEnumerable<string> ToIndexColumns()
        {
            var columns = new List<string>();
            Action<string> addIndex = name =>
            {
                if (!string.IsNullOrEmpty(name))
                {
                    columns.Add(name);
                }
            };

            addIndex(IndexName1);
            addIndex(IndexName2);
            addIndex(IndexName3);
            addIndex(IndexName4);
            addIndex(IndexName5);

            return columns;
        }
    }
}
